package com.imooc.ecommerce.converter;

import com.imooc.ecommerce.constant.GoodsCategory;

import javax.persistence.AttributeConverter;

/**
 * <p>商品类别枚举属性转换器
 *
 * @author Yaxi.Zhang
 * @since 2022/11/12 16:35
 */
public class GoodsCategoryConverter implements AttributeConverter<GoodsCategory, String> {

    @Override
    public String convertToDatabaseColumn(GoodsCategory goodsCategory) {
        return goodsCategory.getCode();
    }

    @Override
    public GoodsCategory convertToEntityAttribute(String code) {
        return GoodsCategory.of(code);
    }

}
